package com.kbs.im.server.handler;

import com.kbs.im.common.protocol.packet.request.LoginRequestPacket;
import com.kbs.im.common.protocol.packet.response.LoginResponsePacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Date;

/**
 * 测试 handler
 *
 * @author zhangzhang
 */
public class TestHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        ByteBuf byteBuf = (ByteBuf) msg;
        LoginRequestPacket requestPacket = (LoginRequestPacket) msg;

        System.out.println(new Date() + ": 服务端读到数据 -> " + requestPacket.toString());

        LoginResponsePacket responsePacket = new LoginResponsePacket();
        responsePacket.setCode("200");
        responsePacket.setMsg("这里是服务器，已经收到你发送的消息：" + requestPacket.toString());
        ctx.channel().writeAndFlush(responsePacket);
    }
}
